import sensor from '@system.sensor';
export default {
    data: {
        title: 'World'
    },
    onDestory(){
        this.unsubscribeAccelerometer();
        this.unsubscribeCompass();
        this.unsubscribeLight();
        this.unsubscribeStepCounter();
        this.unsubscribeBarometer();
        this.unsubscribeHeartRate();
        this.unsubscribeOnBodyState();
        this.unsubscribeDeviceOrientation();
        this.unsubscribeGyroscope();
    },
    subscribeAccelerometer(){
        sensor.subscribeAccelerometer({
            interval: 'normal',
            success: function(ret) {
                console.log('get data x:' + ret.x);
                console.log('get data y:' + ret.y);
                console.log('get data z:' + ret.z);
            },
            fail: function(data, code) {
                console.error('subscribe accelerometer fail, code: ' + code + ', data: ' + data);
            },
        });
    },
    unsubscribeAccelerometer(){
        sensor.unsubscribeAccelerometer();
    },
    subscribeCompass(){
        sensor.subscribeCompass({
            success: function(ret) {
                console.log('get data direction:' + ret.direction);
            },
            fail: function(data, code) {
                console.error('subscribe compass fail, code: ' + code + ', data: ' + data);
            },
        });
    },
    unsubscribeCompass(){
        sensor.unsubscribeCompass();
    },
    subscribeLight(){
        sensor.subscribeLight({
            success: function(ret) {
                console.log('get data intensity:' + ret.intensity);
            },
            fail: function(data, code) {
                console.error('subscribe light fail, code: ' + code + ', data: ' + data);
            },
        });
    },
    unsubscribeLight(){
        sensor.unsubscribeLight();
    },
    subscribeStepCounter(){
        sensor.subscribeStepCounter({
            success: function(ret) {
                console.log('get step value:' + ret.steps);
            },
            fail: function(data, code) {
                console.log('subscribe step count fail, code:' + code + ', data:' + data);
            },
        });
    },
    unsubscribeStepCounter(){
        sensor.unsubscribeStepCounter();
    },
    subscribeBarometer(){
        sensor.subscribeBarometer({
            success: function(ret) {
                console.log('get data value:' + ret.pressure);
            },
            fail: function(data, code) {
                console.log('subscribe barometer fail, code: ' + code + ', data: ' + data);
            },
        });
    },
    unsubscribeBarometer(){
        sensor.unsubscribeBarometer();
    },
    subscribeHeartRate(){
        sensor.subscribeHeartRate({
            success: function(ret) {
                console.log('get heartrate value:' + ret.heartRate);
            },
            fail: function(data, code) {
                console.log('subscribe heart rate fail, code: ' + code + ', data: ' + data);
            },
        });
    },
    unsubscribeHeartRate(){
        sensor.unsubscribeHeartRate();
    },
    subscribeOnBodyState(){
        sensor.subscribeOnBodyState({
            success: function(ret) {
                console.log('get on-body state value:' + ret.value);
            },
            fail: function(data, code) {
                console.log('fail to get on body state, code:' + code + ', data: ' + data);
            },
        });
    },
    unsubscribeOnBodyState(){
        sensor.unsubscribeOnBodyState();
    },
    getOnBodyState(){
        sensor.getOnBodyState({
            success: function(ret) {
                console.log('on body state: ' + ret.value);
            },
            fail: function(data, code) {
                console.log('handling fail, message: ' + data + ', code: ' + code);
            },
        });
    },
    subscribeDeviceOrientation(){
        sensor.subscribeDeviceOrientation({
            interval: 'normal',
            success: function(ret) {
                console.log('get data alpha:' + ret.alpha);
                console.log('get data beta:' + ret.beta);
                console.log('get data gamma:' + ret.gamma);
            },
            fail: function(data, code) {
                console.error('subscribe device orientation fail, code: ' + code + ', data: ' + data);
            }
        });
    },
    unsubscribeDeviceOrientation(){
        sensor.unsubscribeDeviceOrientation();
    },
    subscribeGyroscope(){
        sensor.subscribeGyroscope({
            interval: 'normal',
            success: function(ret) {
                console.log('get data x:' + ret.x);
                console.log('get data y:' + ret.y);
                console.log('get data z:' + ret.z);
            },
            fail: function(data, code) {
                console.error('subscribe gyroscope fail, code: ' + code + ', data: ' + data);
            }
        });
    },
    unsubscribeGyroscope(){
        sensor.unsubscribeGyroscope();
    }


}
